<template>
  <div class="refuse-wrap">
    <div class="reason-box">
      <textarea placeholder="请输入审核拒绝的理由(15字以内)" id="reason" maxlength="15" class="reason" @blur="inputBlur"
                v-model="remark"></textarea>
    </div>
    <div class="btn-box" v-show="hideBtn">
      <button type="button" class="btn leave" @click="cancel">取消</button>
      <button type="button" class="btn cancel" @click="confirm">确定</button>
    </div>
  </div>
</template>

<script>
  import {baseUrl} from "../../config/env";

  export default {
    data() {
      return {
        mechanismId: "",
        id: "",
        remark: "",
        userSign: "",
        docmHeight: document.documentElement.clientHeight,//默认屏幕高度
        showHeight: document.documentElement.clientHeight,//实时屏幕高度
        hideBtn: true//显示或者隐藏
      }
    },
    mounted() {
      let base64 = require('js-base64').Base64;
      this.userSign = base64.decode(sessionStorage.getItem("success"));
      this.mechanismId = this.$route.query.mechanismId;
      this.id = this.$route.query.id;
      window.onresize = () => {
        return (() => {
          this.showHeight = document.body.clientHeight;
        })()
      };
    },
    methods: {
      cancel() {//取消
        this.$router.go(-1);
      },
      inputBlur() {
        window.scrollTo(0, 0);
      },
      confirm() {
        if (this.remark == "" || this.remark == undefined) {
          this.$vux.toast.text("请输入审核拒绝的理由", "middle");
          return;
        }
        this.$vux.loading.show({
          text: '加载中',
        });
        let data = {
          "mechanismId": this.mechanismId,
          "type": 2,
          "id": this.id,
          "remark": this.remark
        };
        let time = (new Date()).getTime();
        let url = baseUrl + "/work_money/set_work_user?timestamp=" + time;
        let param = {"sgin": this.userSign, "timestamp": time};
        let signature = this.$signature(url, param);

        this.axios.post(baseUrl + "/work_money/set_work_user?sgin=" + this.userSign + "&auth=" + signature + "&timestamp=" + time, data).then((res) => {
          let resultObj = res.data;
          this.$vux.loading.hide();
          if (resultObj.code == 0) {
            if (resultObj.data == 0) {
              this.$vux.toast.text("拒绝失败,请重试", "middle");
            } else {
              this.$router.go(-1);
            }
          } else {
            this.$vux.toast.text(resultObj.msg, "middle");
            return;
          }
        }).catch(() => {
          this.$vux.loading.hide();
          this.$vux.toast.text("网络异常", "middle");
        });
      }
    },
    watch: {
      showHeight() {
        if (this.docmHeight > this.showHeight) {
          this.hideBtn = false;
        } else {
          this.hideBtn = true;
        }
      }
    }
  }
</script>

<style lang="stylus" scoped>
  .refuse-wrap
    width: 100%
    height: 100%
    overflow: hidden
    .reason-box
      display: flex
      justify-content: center
      width: 92.53%
      height: 5.293333rem
      margin: 0 auto
      margin-top: 0.346666rem
      .reason
        width: 100%
        height: auto
        padding-left: 0.213rem
        padding-top: 0.187rem
        border: 1px solid rgba(146, 146, 146, 1)
        color: rgba(146, 146, 146, 1)
        font-size: 0.44rem
        resize: none
    .btn-box
      position: fixed
      bottom: 0.48rem
      width: 100%
      text-align: center
      .btn
        width: 45.33%
        height: 1.333rem
        border: 1px solid rgba(60, 175, 255, 1)
        border-radius: 0.107rem
        font-size: 0.48rem
      .leave
        color: rgba(60, 175, 255, 1)
        background: rgba(255, 255, 255, 1)
      .cancel
        margin-left: 0.187rem
        color: rgba(255, 255, 255, 1)
        background: rgba(60, 175, 255, 1)

</style>
